//
//  HMAlphaAnimator.m
//  HMBest
//
//  Created by itcast on 17/4/23.
//  Copyright © 2017年 itcast. All rights reserved.
//

#import "HMAlphaAnimator.h"

@implementation HMAlphaAnimator

// 提供具体转场动画
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    // transitionContext 转场上下文
    UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];//== fromVC.view;
    UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
    
    // 如果需要动画,视图必须存在在UIWindow子视图中
    // 转场容器
    UIView *containerView = [transitionContext containerView];
    // toView添加到转场容器视图中
    [containerView addSubview:toView];
    
    fromView.alpha = 1.0;
    toView.alpha = 0.0;
    
    // 如果实现自定义转场,转场动画会自动锁住事件->防止动画过程中出现问题
    // 转场完成需要解锁事件
    [UIView animateWithDuration:[self transitionDuration:transitionContext]
                     animations:^{
                         fromView.alpha = 0.0;
                         toView.alpha = 1.0;
                     } completion:^(BOOL finished) {
                         [transitionContext completeTransition:YES];
                     }];
    
}


@end
